package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.page.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author ffk
 * @since 2024-06-25
 */
@Api("互动提问的问题")
@RestController
@RequiredArgsConstructor
@RequestMapping("/questions")
public class InteractionQuestionController {


    private  final IInteractionQuestionService interactionQuestionService;

    /**
     * 新增问题
     * @param questionFormDTO
     */
    @ApiOperation("新增问题")
    @PostMapping
    public void addQuestion(@RequestBody QuestionFormDTO questionFormDTO){
        interactionQuestionService.addQuestion(questionFormDTO);
    }

    /**
     * 更新问题
     * @param id
     * @param questionFormDTO
     */
    @ApiOperation("更新问题")
    @PutMapping("/{id}")
    public void updateQuestionById(@PathVariable("id") Long id,@RequestBody QuestionFormDTO questionFormDTO){
        interactionQuestionService.updateQuestionById(id,questionFormDTO);
    }


    /**
     * 用户分页查询问题
     * @param pageQuery
     * @return
     */
    @ApiOperation("用户分页查询问题")
    @GetMapping("page")
    public PageDTO<QuestionVO> userQueryPage(QuestionPageQuery pageQuery){
        return interactionQuestionService.userQueryPage(pageQuery);
    }


    /**
     * 用户 根据问题id查询问题详情
     * @param id
     * @return
     */
    @ApiOperation("根据问题id查询问题详情")
    @GetMapping("/{id}")
    public QuestionVO getQuestionDetailByQuestionId(@PathVariable("id") Long id){
        return interactionQuestionService.getQuestionDetailByQuestionId(id);
    }


    /**
     * 根据id删除问题
     * @param id
     */
    @DeleteMapping("/{id}")
    public void deleteQuestionById(@PathVariable("id") Long id){
        interactionQuestionService.deleteQuestionById(id);
    }

}
